package demo1;

class Money implements Cloneable{
    public double money = 19.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person implements Cloneable{
    public String name;
    public int age = 123;
    public Money m = new Money();

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
        //return super.clone();
    }
}

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        person1.age = 12;
        person1.name = "frost";
        Person person2 = (Person)person1.clone();
        //System.out.println(person2);
        System.out.println(person1.m.money);
        System.out.println(person2.m.money);
        System.out.println("======================");
        person1.m.money = 29.1;
        System.out.println(person1.m.money);
        System.out.println(person2.m.money);
    }
}
